package com.awesome.javademo.algorithm.tree.bean;

import com.awesome.javademo.algorithm.solution.SolutionTreeNode;
import com.awesome.common.util.log.ShowLogUtil;

import java.util.List;

/**
 * Author: JfangZ
 * Email: zhangjingfang@jeejio.com
 * Date: Date:2021/8/9 11:10下午
 * Description:
 */
public class TreeNodeUtil {
    public static TreeNode getTreeNode() {
        TreeNode root = new TreeNode();
        root.val = 3;
        TreeNode left = new TreeNode();
        left.val = 9;
        TreeNode right = new TreeNode();
        right.val = 20;
        TreeNode leftLeft = new TreeNode();
        leftLeft.val = 9;
        TreeNode leftLeftLeft = new TreeNode();
        leftLeftLeft.val = 9;
        TreeNode leftLeftRight = new TreeNode();
        leftLeftRight.val = 100;
        TreeNode rightLeft = new TreeNode();
        rightLeft.val = 15;
        TreeNode rightRight = new TreeNode();
        rightRight.val = 7;
        root.left = left;
        root.right = right;
        root.left.left = leftLeft;
        root.left.left.left = leftLeftLeft;
        root.left.left.right = leftLeftRight;
        root.right.left = rightLeft;
        root.right.right = rightRight;
        List<List<Integer>> lists = SolutionTreeNode.levelOrder(root);
        for (int i = 0; i < lists.size(); i++) {
            for (int j = 0; j < lists.get(i).size(); j++) {
                ShowLogUtil.info("i=" + i + ",j=" + j + "-->" + lists.get(i).get(j));
            }
        }
        return root;
    }


    public static TreeNode getTreeNode1() {
        TreeNode root = new TreeNode();
        root.val = 3;
        TreeNode left = new TreeNode();
        left.val = 9;
        TreeNode right = new TreeNode();
        right.val = 20;
        root.left = left;
        root.right = right;
        TreeNode rightLeft = new TreeNode();
        rightLeft.val = 15;
        TreeNode rightRight = new TreeNode();
        rightRight.val = 7;
        root.right.left = rightLeft;
        root.right.right = rightRight;
        return root;
    }
} 